#!/bin/bash

auto_add_user () {
#$1 = usuário
#$2 = senha
#$3 = limite
#$4 = data
if [ "$1" = "" ]; then
echo -e "${cor[4]} ${txt[114}"
var_exit="1"
fi
if [ "$2" = "" ]; then
echo -e "${cor[4]} ${txt[114}"
var_exit="1"
fi
if [ "$3" = "" ]; then
echo -e "${cor[4]} ${txt[114}"
var_exit="1"
fi
if [ "$4" = "" ]; then
echo -e "${cor[4]} ${txt[114}"
var_exit="1"
fi
if [ "$var_exit" = "1" ]; then
sleep 0.5s
unset var_exit
 else
if [ "$OPENVPN" = "on" ]; then
open_1 $1 $2 30 $3 s
return
fi
useradd -M -s /bin/false $1 -e $4
(echo $2; echo $2) | passwd $1 2>/dev/null
echo -e "${cor[5]} $1 Criado Com Sucesso!"
echo -e "Usuario: $1"
echo -e "Senha: $2"
echo -e "Loguins: $3"
echo -e "Data: $4"
 if [ -e $dir_user/$1 ]; then
rm $dir_user/$1
 fi
touch $dir_user/$1
echo "senha: $senha" >> $dir_user/$1
echo "limite: $limite" >> $dir_user/$1
echo "data: $data" >> $dir_user/$1
fi
}

function_1 () {
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "${cor[4]} ${txt[99]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
for user in `awk -F : '$3 > 900 { print $1 }' /etc/passwd | grep -v "nobody" |grep -vi polkitd |grep -vi systemd-[a-z] |grep -vi systemd-[0-9]`; do
echo -e "${cor[5]} ${txt[100]}"
echo -e "\033[1;31m $user"
if [ -e $dir_user/$user ]; then
pass=$(cat $dir_user/$user | grep "senha" | awk '{print $2}')
data=$(cat $dir_user/$user | grep "data" | awk '{print $2}')
limit=$(cat $dir_user/$user | grep "limite" | awk '{print $2}')
 if [ "$pass" = "" ]; then
pass="ultimate"
 fi
 if [ "$data" = "" ]; then
data=$(date '+%C%y-%m-%d' -d "+30 days")
 fi
 if [ "$limit" = "" ]; then
limit="30"
 fi
 if [ ! -e "$HOME/adm-backup" ]; then
echo "$user $pass $limit $data" > /root/adm-backup
echo -e "${cor[4]} $user\n $pass\n $limit\n $data"
 else
echo "$user $pass $limit $data" >> /root/adm-backup
echo -e "${cor[4]} $user\n $pass\n $limit\n $data"
 fi
else
echo -e "${cor[5]} ${txt[101]}"
echo -e "${cor[5]} ${txt[102]}"
read -p " ©$user ${txt[103]} " pass
read -p " ©$user ${txt[104]} " datas2
number_var $datas2
if [ "$var_number" = "" ]; then
 if [ -e $HOME/adm-backup ]; then
rm $HOME/adm-backup
 fi
echo -e "${cor[1]} =================================== ${cor[0]}"
return
 else
datas="$var_number"
fi
data=$(date '+%C%y-%m-%d' -d "+$datas days")
read -p " ©$user ${txt[105]} " limit2
number_var $limit2
if [ "$var_number" = "" ]; then
 if [ -e $HOME/adm-backup ]; then
rm $HOME/adm-backup
 fi
echo -e "${cor[1]} =================================== ${cor[0]}"
return
 else
limit="$var_number"
fi
 if [ ! -e "$HOME/adm-backup" ]; then
echo "$user $pass $limit $data" > /root/adm-backup
echo -e "${cor[4]} $user\n $pass\n $limit\n $data"
 else
echo "$user $pass $limit $data" >> /root/adm-backup
echo -e "${cor[4]} $user\n $pass\n $limit\n $data"
 fi
fi
echo -e "${cor[1]} =================================== ${cor[0]}"
done
echo "admpro" >> $HOME/adm-backup
echo -e "${cor[5]} ${txt[106]}"
echo -e "${cor[5]} ${txt[107]} \033[1;36m$HOME/adm-backup! ${cor[0]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
}

function_2 () {
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "${cor[4]} ${txt[108]}
 ${txt[109]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
_ba="/root/adm-backup"
read -p " [${txt[110]}]: " -e -i $_ba arq
[[ ! -e "$arq" ]] && {
       cd $HOME
       wget -O backup-adm $arq -o /dev/null
       [[ ! -e "$HOME/backup-adm" ]] && echo -e "${cor[5]} ${txt[111]}" && return 1
       [[ ! $(cat $HOME/backup-adm | egrep -o "admpro") ]] && echo -e "${cor[5]} ${txt[112]}" && return 1
       arq_bkp="$HOME/backup-adm"
       } || {
      [[ ! $(cat $arq | egrep -o "admpro") ]] && echo -e "${cor[5]} ${txt[112]}" && return 1
      arq_bkp="$arq"
      }
echo -e "\033[1;37m ${txt[113]}"
cd /etc/adm-lite
while read backup_adm; do
[[ $(echo "$backup_adm" | egrep -o "admpro") ]] && break
usuario=$(echo "$backup_adm" | awk '{print $1}')
senha=$(echo "$backup_adm" | awk '{print $2}')
limite=$(echo "$backup_adm" | awk '{print $3}')
data=$(echo "$backup_adm" | awk '{print $4}')
echo -e "${cor[1]} =================================== ${cor[0]}"
auto_add_user "$usuario" "$senha" "$limite" "$data"
done < $arq_bkp
echo -e "${cor[1]} =================================== ${cor[0]}"
cd /etc/adm-lite
}

function_3 () {
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "${cor[4]} ${txt[115]}\n ${txt[116]}"
echo -e "${cor[1]} =================================== ${cor[0]}" 
echo 3 > /proc/sys/vm/drop_caches
sysctl -w vm.drop_caches=3 > /dev/null 2>&1
rm -rf /tmp/*
echo -e "${cor[5]} ${txt[117]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
}

function_4 () {
pid_badvpn=$(ps x | grep badvpn | grep -v grep | awk '{print $1}')
echo -e "${cor[1]} =================================== ${cor[0]}"
if [ "$pid_badvpn" = "" ]; then
    echo -e "${cor[4]} ${txt[118]}\n ${txt[119]}\n ${txt[120]}\n ${txt[121]}"
    echo -e "${cor[1]} =================================== ${cor[0]}"
    if [[ ! -e /bin/badvpn-udpgw ]]; then
    cd $HOME
    wget https://www.dropbox.com/s/uu3opxoevth47af/badvpn-udpgw -o /dev/null
    mv -f $HOME/badvpn-udpgw /bin/badvpn-udpgw
    chmod 777 /bin/badvpn-udpgw
    fi
    screen -dmS screen /bin/badvpn-udpgw --listen-addr 127.0.0.1:7300 --max-clients 1000 --max-connections-for-client 10
    [[ "$(ps x | grep badvpn | grep -v grep | awk '{print $1}')" ]] && echo -e "${cor[4]} ${txt[123]}" || echo -e "${cor[4]} ${txt[284]}"
    echo -e "${cor[1]} =================================== ${cor[0]}"
    unset pid_badvpn
    return 0
else
    echo -e "${cor[4]} ${txt[124]}"
    echo -e "${cor[1]} =================================== ${cor[0]}"
    kill -9 $(ps x | grep badvpn | grep -v grep | awk '{print $1'}) > /dev/null 2>&1
    killall badvpn-udpgw > /dev/null 2>&1
    [[ ! "$(ps x | grep badvpn | grep -v grep | awk '{print $1}')" ]] && echo -e "${cor[4]} ${txt[125]}"
    echo -e "${cor[1]} =================================== ${cor[0]}"
    unset pid_badvpn
    fi
}

function_5 () {
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "${cor[4]} ${txt[126]}"
echo -e "${cor[4]} ${txt[127]}"
echo -e "${cor[4]} ${txt[128]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
sleep 1s
if [[ `grep -c "^#ADM" /etc/sysctl.conf` -eq 0 ]]; then
#INSTALA
echo -e "${cor[5]} ${txt[130]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
read -p " ${txt[136]} [s/n]: " -e -i s resp_osta
if [[ "$resp_osta" = 's' ]]; then
unset resp_osta
echo "#ADM" >> /etc/sysctl.conf
echo "net.ipv4.tcp_window_scaling = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 16384 16777216
net.ipv4.tcp_low_latency = 1
net.ipv4.tcp_slow_start_after_idle = 0" >> /etc/sysctl.conf
sysctl -p /etc/sysctl.conf > /dev/null 2>&1
echo -e "${cor[5]} ${txt[137]} TCP"
echo -e "${cor[5]} ${txt[138]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
return
 else
echo -e "${cor[1]} =================================== ${cor[0]}"
return
fi
 else
#REMOVE
echo -e "${cor[5]} ${txt[137]} TCP"
echo -e "${cor[5]} ${txt[139]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
read -p " ${txt[140]} TCP? [s/n]: " -e -i n res_posta
if [[ "$res_posta" = 's' ]]; then
unset res_posta
grep -v "^#ADM
net.ipv4.tcp_window_scaling = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 16384 16777216
net.ipv4.tcp_low_latency = 1
net.ipv4.tcp_slow_start_after_idle = 0" /etc/sysctl.conf > /tmp/syscl && mv -f /tmp/syscl /etc/sysctl.conf
sysctl -p /etc/sysctl.conf > /dev/null 2>&1
echo -e "${cor[5]} ${txt[141]} TCP"
echo -e "${cor[5]} ${txt[142]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
return
 else
echo -e "${cor[1]} =================================== ${cor[0]}"
return
 fi
fi
}

function_6 () {
source fai2ban
}

function_7 () {
echo -e "${cor[1]} ====================================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[157]}\n ${txt[158]}\n ${txt[159]}\n ${txt[160]}\n ${txt[161]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
sleep 2s
if [ -e /etc/squid/squid.conf ]; then
squid_var="/etc/squid/squid.conf"
elif [ -e /etc/squid3/squid.conf ]; then
squid_var="/etc/squid3/squid.conf"
else
echo -e "${cor[5]} ${txt[162]}"
return 1
fi
teste_cache="#CACHE DO SQUID"
if [[ `grep -c "^$teste_cache" $squid_var` -gt 0 ]]; then
  [[ -e ${squid_var}.bakk ]] && {
  echo -e "${cor[5]} ${txt[167]}\n ${txt[168]}"
  mv -f ${squid_var}.bakk $squid_var
  echo -e "${cor[5]} ${txt[165]}"
  echo -e "${cor[1]} ====================================================== ${cor[0]}"
  service squid restart > /dev/null 2>&1
  service squid3 restart > /dev/null 2>&1
  return 0
  }
fi
echo -e "${cor[5]} ${txt[163]}\n ${cor[5]} ${txt[164]}\n ${txt[166]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
_tmp="#CACHE DO SQUID\ncache_mem 200 MB\nmaximum_object_size_in_memory 32 KB\nmaximum_object_size 1024 MB\nminimum_object_size 0 KB\ncache_swap_low 90\ncache_swap_high 95"
[[ "$squid_var" = "/etc/squid/squid.conf" ]] && _tmp+="\ncache_dir ufs /var/spool/squid 100 16 256\naccess_log /var/log/squid/access.log squid" || _tmp+="\ncache_dir ufs /var/spool/squid3 100 16 256\naccess_log /var/log/squid3/access.log squid"
while read s_squid; do
[[ "$s_squid" != "cache deny all" ]] && _tmp+="\n${s_squid}"
done < $squid_var
cp ${squid_var} ${squid_var}.bakk
echo -e "${_tmp}" > $squid_var
echo -e "${cor[5]} ${txt[165]}\n ${txt[168]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
service squid restart > /dev/null 2>&1
service squid3 restart > /dev/null 2>&1
}

function_8 () {
echo -e "${cor[1]} ====================================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[170]}"
echo -e "${cor[5]} ${txt[171]}"
echo -e "${cor[5]} ${txt[172]}"
echo -e "${cor[5]} ${txt[173]} \033[1;31m$HOME"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
meu_ip
echo -e "${cor[2]} |1| >${cor[3]} ${txt[169]}"
echo -e "${cor[2]} |2| >${cor[3]} ${txt[174]}"
echo -e "${cor[2]} |3| >${cor[3]} ${txt[175]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
read -p " |1-3|: " arquivo_online_adm
number_var $arquivo_online_adm
if [ "$var_number" = "" ]; then
return
 else
online_adm="$var_number"
fi
if [ "$online_adm" -gt 3 ]; then
echo -e "${cor[5]} ${txt[175]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
return
fi
if [ "$online_adm" = 3 ]; then
echo -e "${cor[1]} ====================================================== ${cor[0]}"
for my_arqs in `ls /var/www/html`; do
if [ "$my_arqs" != "index.html" ]; then
 if [ ! -d "$my_arqs" ]; then
echo -e " \033[1;36mhttp://$IP:81/$my_arqs\033[0m"
 fi
fi
done
echo -e "${cor[1]} ====================================================== ${cor[0]}"
return
fi
if [ "$online_adm" = 2 ]; then
echo -e "${cor[1]} ====================================================== ${cor[0]}"
unset _cont
_cont="1"
for my_arqs in `ls /var/www/html`; do
if [ "$my_arqs" != "index.html" ]; then
 if [ ! -d "$my_arqs" ]; then
select_arc[$_cont]="$my_arqs"
echo -e "${cor[2]} |$_cont| >${cor[3]}$my_arqs - \033[1;36mhttp://$IP:81/$my_arqs\033[0m"
_cont=$(($_cont + 1))
 fi
fi
done
_cont=$(($_cont - 1))
echo -e "${cor[1]} ====================================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[177]}"
read -p " | 1 - $_cont |: " slct
number_var $slct
if [ "$var_number" = "" ]; then
return
 else
slct="$var_number"
fi
unset _cont
arquivo_move="${select_arc[$slct]}"
 if [ "$arquivo_move" = "" ]; then
echo -e "${cor[5]} ${txt[178]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
return
 fi
rm -rf /var/www/html/$arquivo_move > /dev/null 2>&1
rm -rf /var/www/$arquivo_move > /dev/null 2>&1
echo -e "${cor[5]} ${txt[179]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
return
fi
unset _cont
_cont="1"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[181]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
for my_arqs in `ls $HOME`; do
if [ ! -d "$my_arqs" ]; then
select_arc[$_cont]="$my_arqs"
echo -e "${cor[2]} |$_cont| >${cor[3]}$my_arqs"
_cont=$(($_cont + 1))
fi
done
_cont=$(($_cont - 1))
echo -e "${cor[1]} ====================================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[177]}"
read -p " | 1 - $_cont |: " slct
number_var $slct
if [ "$var_number" = "" ]; then
return
 else
slct="$var_number"
fi
unset _cont
arquivo_move="${select_arc[$slct]}"
if [ "$arquivo_move" = "" ]; then
echo -e "${cor[5]} ${txt[178]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
return
fi
if [ ! -d /var ]; then
mkdir /var
fi
if [ ! -d /var/www ]; then
mkdir /var/www
fi
if [ ! -d /var/www/html ]; then
mkdir /var/www/html
fi
if [ ! -e /var/www/html/index.html ]; then
touch /var/www/html/index.html
fi
if [ ! -e /var/www/index.html ]; then
touch /var/www/index.html
fi
chmod -R 755 /var/www
cp $HOME/$arquivo_move /var/www/$arquivo_move
cp $HOME/$arquivo_move /var/www/html/$arquivo_move
echo -e "${cor[1]} ====================================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[180]}"
echo -e "\033[1;36m http://$IP:81/$arquivo_move\033[0m"
echo -e "${cor[5]} ${txt[179]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
}

function_9 () {
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "${cor[4]} ${txt[184]}"
echo -e "${cor[1]} =================================== ${cor[0]}"
ping=$(ping -c1 google.com |awk '{print $8 $9}' |grep -v loss |cut -d = -f2 |sed ':a;N;s/\n//g;ta')
starts_test=$(python ./speedtest.py)
down_load=$(echo "$starts_test" | grep "Download" | awk '{print $2,$3}')
up_load=$(echo "$starts_test" | grep "Upload" | awk '{print $2,$3}')
echo -e "${cor[5]} ${txt[185]}: $ping"
echo -e "${cor[5]} ${txt[186]}: $up_load"
echo -e "${cor[5]} ${txt[187]}: $down_load"
echo -e "${cor[1]} =================================== ${cor[0]}"
}

function_10 () {
null="\033[1;31m"
echo -e "${cor[1]} ============================================================================ ${cor[0]}"
if [ ! /proc/cpuinfo ]; then
echo -e "${cor[4]} ${txt[188]}"
echo -e "${cor[1]} ============================================================================ ${cor[0]}"
return
fi
if [ ! /etc/issue.net ]; then
echo -e "${cor[4]} ${txt[188]}"
echo -e "${cor[1]} ============================================================================ ${cor[0]}"
return
fi
if [ ! /proc/meminfo ]; then
echo -e "${cor[4]} ${txt[188]}"
echo -e "${cor[1]} ============================================================================ ${cor[0]}"
return
fi
totalram=$(free | grep Mem | awk '{print $2}')
usedram=$(free | grep Mem | awk '{print $3}')
freeram=$(free | grep Mem | awk '{print $4}')
swapram=$(cat /proc/meminfo | grep SwapTotal | awk '{print $2}')
system=$(cat /etc/issue.net)
clock=$(lscpu | grep "CPU MHz" | awk '{print $3}')
based=$(cat /etc/*release | grep ID_LIKE | awk -F "=" '{print $2}')
processor=$(cat /proc/cpuinfo | grep "model name" | uniq | awk -F ":" '{print $2}')
cpus=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ "$system" ]; then
echo -e "${cor[5]} ${txt[189]}: ${null}$system"
else
echo -e "${cor[5]} ${txt[189]}: ${null}???"
fi
if [ "$based" ]; then
echo -e "${cor[5]} ${txt[190]}: ${null}$based"
else
echo -e "${cor[5]} ${txt[190]}: ${null}???"
fi
if [ "$processor" ]; then
echo -e "${cor[5]} ${txt[191]}: ${null}$processor x$cpus"
else
echo -e "${cor[5]} ${txt[191]}: ${null}???"
fi
if [ "$clock" ]; then
echo -e "${cor[5]} ${txt[192]}: ${null}$clock MHz"
else
echo -e "${cor[5]} ${txt[192]}: ${null}???"
fi
echo -e "${cor[5]} ${txt[193]}: ${null}$(ps aux  | awk 'BEGIN { sum = 0 }  { sum += sprintf("%f",$3) }; END { printf " " "%.2f" "%%", sum}')"
echo -e "${cor[5]} ${txt[194]}: ${null}$(($totalram / 1024))"
echo -e "${cor[5]} ${txt[195]}: ${null}$(($usedram / 1024))"
echo -e "${cor[5]} ${txt[196]}: ${null}$(($freeram / 1024))"
echo -e "${cor[5]} ${txt[197]}: ${null}$(($swapram / 1024))MB"
echo -e "${cor[5]} ${txt[198]}: ${null}$(uptime)"
echo -e "${cor[5]} ${txt[199]}: ${null}$(hostname)"
echo -e "${cor[5]} ${txt[200]}: ${null}$(ip addr | grep inet | grep -v inet6 | grep -v "host lo" | awk '{print $2}' | awk -F "/" '{print $1}')"
echo -e "${cor[5]} ${txt[201]}: ${null}$(uname -r)"
echo -e "${cor[5]} ${txt[202]}: ${null}$(uname -m)"
echo -e "${cor[1]} ============================================================================ ${cor[0]}"
return
}

function_11 () {
payload="/etc/payloads"
if [ ! -f "$payload" ]; then
echo -e "${cor[5]} $payload ${txt[213]}"
echo -e "${cor[5]} ${txt[214]}"
return
fi
echo -e "${cor[1]} ====================================================== ${cor[0]}"
echo -e "${cor[2]} |1| >${cor[3]} ${txt[215]}"
echo -e "${cor[2]} |2| >${cor[3]} ${txt[216]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
read -p " | 1 - 2 |: " var_pay
number_var $var_pay
if [ "$var_number" = "" ]; then
echo -e "\033[1;31m ${txt[217]}"
return
 else
var_payload="$var_number"
fi
if [ "$var_payload" -gt "2" ]; then
echo -e "\033[1;31m ${txt[217]}"
return
fi
if [ "$var_payload" = "1" ]; then
echo -e "${cor[4]} ${txt[215]}"
echo -e "${cor[5]} ${txt[218]} $payload:"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
echo -e "${cor[1]} ====================================================== ${cor[0]}"
echo -e " ${txt[219]}"
echo -e " ${txt[220]}" 
read -p " Host: " hos
if [[ $hos != \.* ]]; then
echo -e "${cor[5]} ${txt[220]}"
return
fi
host="$hos/"
if [[ -z $host ]]; then
echo -e "${cor[5]} ${txt[221]}"
return
fi
if [[ `grep -c "^$host" $payload` -eq 1 ]]; then
echo -e "${cor[5]} ${txt[222]}"
return
fi
echo "$host" >> $payload && grep -v "^$" $payload > /tmp/a && mv /tmp/a $payload
echo -e "${cor[5]} ${txt[223]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
echo -e "${cor[1]} ====================================================== ${cor[0]}"
 if [ ! -f "/etc/init.d/squid" ]; then
service squid3 reload > /dev/null 2>&1
service squid3 restart > /dev/null 2>&1
 else
/etc/init.d/squid reload
service squid restart > /dev/null 2>&1
 fi	
return
fi

if [ "$var_payload" = "2" ]; then
echo -e "${cor[4]} ${txt[216]}"
echo -e "${cor[5]} ${txt[218]} $payload:"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
echo -e "${cor[1]} ====================================================== ${cor[0]}"
read -p " ${txt[224]} ${txt[220]}: " hos
if [[ $hos != \.* ]]; then
echo -e "${cor[5]} ${txt[220]}"
return
fi
host="$hos/"
if [[ -z $host ]]; then
echo -e "${cor[5]} ${txt[221]}"
return
fi
if [[ `grep -c "^$host" $payload` -ne 1 ]]; then
echo -e "${cor[5]} ${txt[225]}"
return
fi
grep -v "^$host" $payload > /tmp/a && mv /tmp/a $payload
echo -e "${cor[5]} ${txt[223]}"
echo -e "${cor[1]} ====================================================== ${cor[0]}"
cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
echo -e "${cor[1]} ====================================================== ${cor[0]}"
 if [ ! -f "/etc/init.d/squid" ]; then
service squid3 reload > /dev/null 2>&1
service squid3 restart > /dev/null 2>&1
 else
/etc/init.d/squid reload
service squid restart > /dev/null 2>&1
 fi	
return
fi
}

criar_pay () {
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[258]}"
echo -e "${cor[5]} ${txt[259]}"
echo -e "${cor[5]} ${txt[260]}"
echo -e "${cor[5]} ${txt[261]}"
echo -e "${cor[1]} =================================== ${cor[3]}"
read -p " => " valor1
if [ "$valor1" = "" ]; then
echo -e "${cor[5]} ${txt[262]}"
return
fi
meu_ip
valor2="$IP"
if [ "$valor2" = "" ]; then
valor2="127.0.0.1"
fi
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[264]} ${cor[3]}"
echo -e " 1-GET"
echo -e " 2-CONNECT"
echo -e " 3-PUT"
echo -e " 4-OPTIONS"
echo -e " 5-DELETE"
echo -e " 6-HEAD"
echo -e " 7-TRACE"
echo -e " 8-PROPATCH"
echo -e " 9-PATCH"
echo -e "${cor[1]} =================================== ${cor[3]}"
read -p " => " valor3
case $valor3 in
1)
req="GET"
;;
2)
req="CONNECT"
;;
3)
req="PUT"
;;
4)
req="OPTIONS"
;;
5)
req="DELETE"
;;
6)
req="HEAD"
;;
7)
req="TRACE"
;;
8)
req="PROPATCH"
;;
9)
req="PATCH"
;;
*)
req="GET"
;;
esac
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "${cor[5]} ${txt[265]}"
echo -e "${cor[5]} ${txt[266]} ${cor[3]}"
echo -e " 1-realData"
echo -e " 2-netData"
echo -e " 3-raw"
echo -e "${cor[1]} =================================== ${cor[0]}"
read -p " => " valor4
case $valor4 in
1)
in="realData"
;;
2)
in="netData"
;;
3)
in="raw"
;;
*)
in="netData"
;;
esac
echo -e "${cor[1]} =================================== ${cor[0]}"
name=$(echo $valor1 | awk -F "/" '{print $2'})
if [ "$name" = "" ]; then
name=$(echo $valor1 | awk -F "/" '{print $1'})
fi
esquelet="/etc/adm-lite/payloads"
sed -s "s;realData;abc;g" $esquelet > $HOME/$name.txt
sed -i "s;netData;abc;g" $HOME/$name.txt
sed -i "s;raw;abc;g" $HOME/$name.txt
sed -i "s;abc;$in;g" $HOME/$name.txt
sed -i "s;get;$req;g" $HOME/$name.txt
sed -i "s;mhost;$valor1;g" $HOME/$name.txt
sed -i "s;mip;$valor2;g" $HOME/$name.txt
if [ "$(cat $HOME/$name.txt | egrep -o "$valor1")" = "" ]; then
echo -e ""
echo -e "${cor[3]} ${txt[267]} \033[1;36m${txt[268]}"
rm $HOME/$name.txt
return
fi
echo -e "${cor[3]} ${txt[269]}"
echo -e "${cor[3]} ${txt[270]} \033[1;31m$HOME/$name.txt"
return
}

fun_bar () {
comando="$1"
 (
[[ -e $HOME/fim ]] && rm $HOME/fim
$comando -y > /dev/null 2>&1
touch $HOME/fim
 ) & > /dev/null
echo -ne "\033[1;33m ["
while true; do
   for((i=0; i<=10; i++)); do
   echo -ne "\033[1;31m#"
   sleep 0.3s
   done
   [[ -e $HOME/fim ]] && {
   rm $HOME/fim
   break
   }
   echo
   echo -ne "\033[1;33m ["
done
echo -e "\033[1;33m]\033[1;31m -\033[1;32m 100%\033[1;37m"
}

vnc_fun () {
echo -e "${cor[1]} =================================== ${cor[0]}"
if [ -d  /root/.vnc/ ];then
vnc=$(ls /root/.vnc/ | grep :1.pid)
else
vnc=""
fi
meu_ip
if [[ $vnc = "" ]]; then
echo -ne " ${txt[312]} [S/N]: "; read x
[[ $x = @(n|N) ]] && echo -e "${cor[1]} =================================== ${cor[0]}" && return
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e " \033[1;36mInstalling VNC:"
fun_bar 'apt-get install xfce4 xfce4-goodies gnome-icon-theme tightvncserver'
echo -e " \033[1;36mInstalling DEPENDENCE:"
fun_bar 'apt-get install iceweasel'
echo -e " \033[1;36mInstalling FIREFOX:"
fun_bar 'apt-get install firefox'
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "\033[1;33m ${txt[308]}\033[1;32m"
echo -e "${cor[1]} =================================== ${cor[0]}"
vncserver
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e " ${txt[309]} 5901"
echo -e " Ex: $IP:5901\033[1;32m"
echo -e " ${txt[310]} "
echo -e " ${txt[311]} VNC VIWER"
elif [[ $vnc != "" ]]; then
echo -e " ${txt[312]} [S/N]: "; read x
[[ $x = @(n|N) ]] && echo -e "${cor[1]} =================================== ${cor[0]}" && return
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e " \033[1;36mremoving VNC:"
fun_bar 'apt-get purge xfce4 xfce4-goodies gnome-icon-theme tightvncserver'
echo -e "\033[1;36m removing DEPENDENCES:"
fun_bar 'apt-get purge iceweasel'
echo -e "\033[1;36m removing FIREFOX:"
fun_bar 'apt-get purge firefox'
vncserver -kill :1 > /dev/null
vncserver -kill :2 > /dev/null
vncserver -kill :3 > /dev/null
fi
echo -e "${cor[1]} =================================== ${cor[0]}"
}

block_torrent () {
mportas () {
unset portas
portas_var=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
while read port; do
var1=$(echo $port | awk '{print $1}') && var2=$(echo $port | awk '{print $9}' | awk -F ":" '{print $2}')
[[ "$(echo -e $portas|grep "$var1 $var2")" ]] || portas+="$var1 $var2\n"
done <<< "$portas_var"
i=1
echo -e "$portas"
}
fun_ip () {
MEU_IP=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
MEU_IP2=$(wget -qO- ipv4.icanhazip.com)
[[ "$MEU_IP" != "$MEU_IP2" ]] && IP="$MEU_IP2" || IP="$MEU_IP"
}
barra="${cor[1]} =================================== ${cor[0]}"
[[ -e /etc/adm-lite/idioma_menuinst ]] && id="$(cat /etc/adm-lite/idioma_menuinst)" || id=pt
[[ $(iptables -h|wc -l) -lt 5 ]] && apt-get install iptables -y > /dev/null 2>-1
NIC=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | head -1)
echo -e "$barra\n $(source trans -b pt:${id} "Essas configuracoes so Devem ser adicionadas")"
echo -e " $(source trans -b pt:${id} "apos a vps estar totalmente configurada!")\n$barra"
echo -e " $(source trans -b pt:${id} "Deseja Prosseguir?")"
read -p " [S/N]: " -e -i n PROS
[[ $PROS = @(s|S|y|Y) ]] || return 1
fun_ip #Pega IP e armazena em uma variavel
#Inicia Procedimentos
#Parametros iniciais
echo 'iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT' > ./torrent-adm
chmod +x ./torrent-adm
#libera DNS
echo 'iptables -A OUTPUT -p tcp --dport 53 -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -m state --state NEW -j ACCEPT' >> ./torrent-adm
#Liberar DHCP
echo 'iptables -A OUTPUT -p tcp --dport 67 -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p udp --dport 67 -m state --state NEW -j ACCEPT' >> ./torrent-adm
#Liberando Serviços Ativos
list_ips=$(mportas|awk '{print $2}')
while read PORT; do
echo "iptables -A INPUT -p tcp --dport $PORT -j ACCEPT
iptables -A INPUT -p udp --dport $PORT -j ACCEPT
iptables -A OUTPUT -p tcp --dport $PORT -j ACCEPT
iptables -A OUTPUT -p udp --dport $PORT -j ACCEPT
iptables -A FORWARD -p tcp --dport $PORT -j ACCEPT
iptables -A FORWARD -p udp --dport $PORT -j ACCEPT
iptables -A OUTPUT -p tcp -d $IP --dport $PORT -m state --state NEW -j ACCEPT
iptables -A OUTPUT -p udp -d $IP --dport $PORT -m state --state NEW -j ACCEPT" >> ./torrent-adm
done <<< "$list_ips"
#Bloqueando Ping
echo 'iptables -A INPUT -p icmp --icmp-type echo-request -j DROP' >> ./torrent-adm
#Liberar WEBMIN
echo 'iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 10000 -j ACCEPT' >> ./torrent-adm
#Bloqueando torrent
echo "iptables -t nat -A PREROUTING -i $NIC -p tcp --dport 6881:6889 -j DNAT --to-dest $IP
iptables -A FORWARD -p tcp -i $NIC --dport 6881:6889 -d $IP -j REJECT
iptables -A OUTPUT -p tcp --dport 6881:6889 -j DROP
iptables -A OUTPUT -p udp --dport 6881:6889 -j DROP" >> ./torrent-adm
echo 'iptables -A FORWARD -m string --algo bm --string "BitTorrent" -j DROP
iptables -A FORWARD -m string --algo bm --string "BitTorrent protocol" -j DROP
iptables -A FORWARD -m string --algo bm --string "peer_id=" -j DROP
iptables -A FORWARD -m string --algo bm --string ".torrent" -j DROP
iptables -A FORWARD -m string --algo bm --string "announce.php?passkey=" -j DROP
iptables -A FORWARD -m string --algo bm --string "torrent" -j DROP
iptables -A FORWARD -m string --algo bm --string "announce" -j DROP
iptables -A FORWARD -m string --algo bm --string "info_hash" -j DROP
iptables -A FORWARD -m string --string "get_peers" --algo bm -j DROP
iptables -A FORWARD -m string --string "announce_peer" --algo bm -j DROP
iptables -A FORWARD -m string --string "find_node" --algo bm -j DROP' >> ./torrent-adm
./torrent-adm
echo -e "$barra\n $(source trans -b pt:${id} "Aplicado!")\n$barra"
}

paybrute () {
chmod +x ./paysnd.sh
./paysnd.sh
}

function_16 () {
echo -e "${cor[3]} "${txt[333]}""
read -p " [S/N]: " -e -i n rebt
[[ "$rebt" = @(s|S|y|Y) ]] && {
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "\033[1;36m ${txt[334]}"
sleep 3s
echo -e "${cor[1]} =================================== ${cor[0]}"
echo -e "\033[1;36m OK"
sleep 1s
sudo reboot
} 
}

[[ "$1" = "1" ]] && function_1
[[ "$1" = "2" ]] && function_2
[[ "$1" = "3" ]] && function_3
[[ "$1" = "4" ]] && function_4
[[ "$1" = "5" ]] && function_5
[[ "$1" = "6" ]] && function_6
[[ "$1" = "7" ]] && function_7
[[ "$1" = "8" ]] && function_8
[[ "$1" = "9" ]] && function_9
[[ "$1" = "10" ]] && function_10
[[ "$1" = "11" ]] && function_11
[[ "$1" = "12" ]] && criar_pay
[[ "$1" = "13" ]] && vnc_fun
[[ "$1" = "14" ]] && paybrute
[[ "$1" = "15" ]] && block_torrent
[[ "$1" = "16" ]] && function_16
####_Eliminar_Tmps_####
[[ -e $_tmp ]] && rm $_tmp
[[ -e $_tmp2 ]] && rm $_tmp2
[[ -e $_tmp3 ]] && rm $_tmp3
[[ -e $_tmp4 ]] && rm $_tmp4
